[#include "../../common/html.ftl" /]
[@html]
    [@head title="系统配置" css=["fw", "bootstrap-table"] /]
    [@body]
        [#--主体内容--]
        [@main ]
            <div class="am-g am-radius fw-tables">
                [#--表格主体内容--操作栏--]
                [@mainHeader]
                    [#--[@shiro.hasPermission name="system:config:add"]--]
                    <button class="am-btn am-btn-success am-radius" onclick="$.operate.addFull()">添加</button>
                    [#--[/@shiro.hasPermission]--]
                    [#--[@shiro.hasPermission name="system:config:remove"]--]
                    <button class="am-btn am-btn-danger am-radius multiple am-disabled" onclick="$.operate.removeAll()">删除</button>
                    [#--[/@shiro.hasPermission]--]
                    [#--[@shiro.hasPermission name="system:config:remove"]--]
                    <button class="am-btn am-btn-black am-radius" onclick="refreshCache()">刷新缓存</button>
                    [#--[/@shiro.hasPermission]--]
                [/@mainHeader]

                [#--表格主体内容--搜索栏--]
                [@searchForm searchId="form-config-search" ]
                    <div class="am-form-group">
                        <input type="text" name="configName" class="am-form-field am-input-sm am-radius" placeholder="参数名称">
                    </div>
                    <div class="am-form-group">
                        <input type="text" name="configKey" class="am-form-field am-input-sm am-radius" placeholder="参数键名">
                    </div>
                    <div class="am-form-group">
                        <select name="configType" class="am-radius" data-am-selected placeholder="是否内置参数">
                            <option value=""></option>
                            [#list dict.getType("sys_yes_no") as dict]
                                <option value="${dict.dictValue}">${dict.dictLabel}</option>
                            [/#list]
                        </select>
                    </div>
                    <div class="am-form-group">
                        <div class="am-form-group am-form-icon">
                            <i class="am-icon-calendar"></i>
                            <input type="text" name="params[beginTime]" class="am-form-field am-input-sm am-radius" placeholder="创建时间-开始"
                                   data-am-datepicker readonly/>
                        </div>
                        <div class="am-form-group am-form-icon">
                            <i class="am-icon-calendar"></i>
                            <input type="text" name="params[endTime]" class="am-form-field am-input-sm am-radius" placeholder="创建时间-结束"
                                   data-am-datepicker readonly/>
                        </div>
                    </div>
                [/@searchForm]

                <div class="fw-table">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        [/@main]

        [#--PC/APP 右侧悬浮按钮--]
        [@rightToolbar /]

        [@script js=["fw", "bootstrap-table"]]
            <script type="text/javascript">
                [#--var editFlag = "${hasPermission('system:config:view')}";--]
                [#--var removeFlag = "${hasPermission('system:config:remove')}";--]
                var editFlag = "";
                var removeFlag ="";
                var datas = ${convert.toJson(dict.getType("sys_yes_no"))};
                var isAdministrator = ${convert.toJson(common.isAdministrator())};

                var prefix = ctx + "osfw/system/config/config";

                $(function () {
                    var options = {
                        url: prefix + "/list",
                        createUrl: prefix + "/add",
                        updateUrl: prefix + "/edit/{id}",
                        removeUrl: prefix + "/remove",
                        sortName: "createTime",
                        sortOrder: "asc",
                        modalName: "参数",
                        uniqueId: "configId",
                        columns: [{
                            checkbox: true
                        },
                            {
                                title: "序号",
                                formatter: function (value, row, index) {
                                    return $.table.serialNumber(index);
                                }
                            },
                            {
                                field: 'configName',
                                title: '参数名称',
                                formatter: function (value, row, index) {
                                    return $.table.tooltip(value, 15);
                                }
                            },
                            {
                                field: 'configKey',
                                title: '参数键名'
                            },
                            {
                                field: 'configValue',
                                title: '参数键值',
                                formatter: function (value, row, index) {
                                    return $.table.tooltip(value, 15);
                                }
                            },
                            {
                                visible: isAdministrator ? true : false,
                                switchable: isAdministrator ? true : false,
                                field: 'configType',
                                title: '系统内置',
                                formatter: function (value, row, index) {
                                    return $.table.selectDictLabel(datas, value);
                                }
                            },
                            {
                                title: '操作',
                                cellStyle: operCellStyle,
                                formatter: function (value, row, index) {
                                    var actions = [];
                                    actions.push('<a class="am-badge am-badge-transparent am-radius ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.configId + '\')">编辑</a> ');
                                    if(isAdministrator){
                                        actions.push('<a class="am-badge am-badge-transparent am-radius ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.configId + '\')">删除</a>');
                                    }
                                    return actions.join('');
                                }
                            }]
                    };
                    $.table.init(options);
                });

                /** 清理参数缓存 */
                function refreshCache() {
                    $.operate.get(prefix + "/refreshCache");
                }
            </script>
        [/@script]
    [/@body]
[/@html]
